package cn.sinata.wanglin.mine.activity;
import android.content.DialogInterface;
import android.view.View;

import com.hyphenate.EMCallBack;
import com.hyphenate.chat.EMClient;
import com.xilada.xldutils.activitys.TitleActivity;
import com.xilada.xldutils.utils.ActivityUtil;
import com.xilada.xldutils.utils.DialogUtils;
import com.xilada.xldutils.utils.SharedPreferencesUtils;

import butterknife.OnClick;
import cn.sinata.wanglin.R;
import cn.sinata.wanglin.commonutils.Constant;
import cn.sinata.wanglin.net.API;
import cn.sinata.wanglin.utils.ShareUtils;

/**
 * app设置页面：账户安全和意见反馈那些
 */
public class AppsettingActivity extends TitleActivity {
    @Override
    protected int setContentId() {
        return R.layout.activity_appsetting;
    }

    @Override
    protected void initView() {
        super.initView();
        setTitle("设置");
    }

    @OnClick({R.id.ttlv_account_safe, R.id.ttlv_feed_back,
            R.id.ttlv_notice,R.id.ttlv_private,
            R.id.ttlv_share_friends,R.id.ttlv_platform_agreement,
            R.id.ttlv_about_us,R.id.ttlv_clearcache,R.id.tv_sign_out})
    void onClick(View v) {
        switch (v.getId()) {
            case R.id.ttlv_account_safe:
                //描述:账户安全
                ActivityUtil.create(mContext).go(AccountSafeActivity.class)
                        .start();
                break;
            case R.id.ttlv_feed_back:
                //描述:意见反馈
                ActivityUtil.create(mContext).go(FeedBackActivity.class)
                        .start();
                break;
            case R.id.ttlv_notice:
                //描述:通知设置
                ActivityUtil.create(mContext).go(NotifcationActivity.class)
                        .start();
                break;
            case R.id.ttlv_private:
                //描述:隐私设置
                ActivityUtil.create(mContext).go(PrivateSettingActivity.class)
                        .start();
                break;
            case R.id.ttlv_share_friends:
                //描述:分享好友
                String userid=SharedPreferencesUtils.getString(Constant.SP_USERID);
                String baseurl2 = API.BASE_URL+"app/system/getShare?userId="+userid+"&url=test";
                ShareUtils.share(AppsettingActivity.this,"找小区，找物业","开心网邻",baseurl2);
                break;
            case R.id.ttlv_platform_agreement:
                //描述:平台协议
                ActivityUtil.create(mContext).go(PlatformAgreementActivity.class)
                        .put("url",API.URL_USERAGREEMENT).start();
                break;
            case R.id.ttlv_about_us:
                //描述:关于我们
                ActivityUtil.create(mContext).go(AboutUsActivity.class)
                        .put("url", API.URL_ABOUTUS)
                        .start();
                break;
            case R.id.ttlv_clearcache:
                //描述:清楚缓存
                showToast("清除成功！");
                break;
            case R.id.tv_sign_out:
                //描述:退出登录
                DialogUtils.createNoticeDialog(this, "请注意", "确定退出登录？", "确定", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        EMClient.getInstance().logout(true, new EMCallBack() {
                            @Override
                            public void onSuccess() {
                                boolean fristtoapp=SharedPreferencesUtils.getBoolean(Constant.SP_FRIST_TO_APP,true);
                                SharedPreferencesUtils.clear();

                                closeAll();
                                ActivityUtil.create(mContext).go(LoginStyleActivity.class)
                                        .start();
                                SharedPreferencesUtils.save(Constant.SP_FRIST_TO_APP,fristtoapp);
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        showToast("退出成功");
                                    }
                                });
                                finish();
                            }

                            @Override
                            public void onError(int i, String s) {
                                runOnUiThread(new Runnable() {
                                    @Override
                                    public void run() {
                                        showToast("退出失败");
                                    }
                                });

                            }

                            @Override
                            public void onProgress(int i, String s) {

                            }
                        });

                    }
                });
                break;
        }
    }
}
